home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
util
/
cli
/
0utils.lha
/
0Utils
/
Exists.data
< prev
next >
Wrap
Text File
|
1995-08-19
|
3KB
|
138 lines
#ifdef TPLTER
Exists = {
SHORT = {{ determine, if a file exists }};
DESCRIPTION = {{
Get one filename on Commandline
and write to StdOut if it exists
Exists gets a filename and outputs if it exists.
The resulting string is sent to STDOUT.
RESULT
if NAME is set the filename if the file exists,
or empty string if not else 1/0
}};
BUGS = {{
We use 'Lock' to check the file, so an exclusively
locked file is not recognized.
We currently do not set ERROR_FILE_NOT_FOUND if
Exists does not find a file
}};
EXAMPLES = {{
>Exists Sys:
1
>Exists c:copy NAME
c:copy
>Exists jabba:the:hutt
0
}};
TODO = {{
Use another way than 'Lock' to determine
the existance
}};
HISTORY = {{
20-03-94 b_noll created
03-02-95 b_noll created (had forgotten the first version =8-})
11-02-95 b_noll added FULL Keyword
20-02-95 b_noll restructured source
21-02-95 b_noll added version/format-prefix/offset
20-03-95 b_noll added args diagnostics
19-08-95 b_noll created .data file
}};
Template = "FILE/A,NAME/S,FULL/S";
Arguments = {{
STRPTR file;
ULONG name;
ULONG full;
}};
version = "1.3";
body = {{
APTR pw;
struct Process *p;
STRPTR ostr;
BPTR lock;
if ((p = (struct Process *)FindTask(NULL))) {
pw = p->pr_WindowPtr;
p->pr_WindowPtr = (APTR)-1;
} /* if */
/* ---- Existance check: rv==0->Exists, rv==5->n/e */
retval = RETURN_WARN;
{
#if 1
UBYTE buffer[MAXPATHLEN];
if ((lock = Lock(argv->file, ACCESS_READ))) {
retval = RETURN_OK;
if (argv->full) {
NameFromLock(lock, buffer, sizeof(buffer));
ostr = buffer;
} else if (argv->name) {
ostr = argv->file;
} else {
ostr = "1";
} /* if */
UnLock (lock);
} else if (IoErr() == ERROR_OBJECT_IN_USE) {
retval = RETURN_OK;
ostr = (argv->name || argv->full) ? argv->file : "1";
} else {
ostr = (argv->name || argv->full) ? "" : "0";
} /* if */
#else
struct AnchorPath *ap;
UBYTE apb[sizeof (*ap) + 8 + MATHPATHLEN];
ap = (void *)(((ULONG)apb + 7) & ~7);
ap->ap_Strlen = MAXPATHLEN;
ap->ap_BreakBits = 0;
ap->ap_FoundBreak = 0;
ap->ap_Flags = 0;
error = MatchFirst(argv->file, ap);
MathEnd (ap);
if (!error) {
retval = RETURN_OK;
ostr = (argv->full) ? ap->ap_Buf :
(argv->name) ? argv->file : "1";
} else {
ostr = (argv->name || argv->full) ? "" : "0";
} /* if */
#endif
/* ----- Result output, either boolean(0/1) or named (name/"") */
PutStr( ostr );
PutStr( "\n" );
}
if (p != NULL) {
p->pr_WindowPtr = pw;
} /* if */
}};
};
#endif